from ECshop.common.base import create_browser,Base
from ECshop.common.base import create_browser_op
import time
class Page_add_addr(Base):
    #前置条件的标签
    url='http://localhost:8080/ecshop/user.php'
    cart_click=('xpath',("//div[@class='cart']/a"))
    fuz_content = ('link text', '服装')
    add_pag = ('xpath', "//img[@class='goodsimg']")
    add_cart = ('xpath', "//img[@src='themes/default/images/buybtn1.png']")  # 添加包到购物车
    buy = ('xpath', ("//td[@align='right']/a/img"))  # 结算
    #地址页面的标签
    S_select=('name','province')
    C_select=('name','city')
    q_slect=('name','district')
    name=('name','consignee')
    addr=('name','address')
    tel=('name','tel')
    addr_click=('xpath',"//td[@align='center']/input")  #配送到这个地址的按钮
    addr_info=('xpath',"//form[@name='theForm']/div[3]/table[@align='center']/tbody/tr")#获取地址信息
    update_addr_click=('xpath',"//form[@name='theForm']/div[3]/h6/span/a") #修改地址按钮
    st_click=('xpath',"//table[@ide='shippingTable']/tbody/tr/tr/td[@valign='top']/input") #申通的点击按钮
    yz_click=('xpath',"//input[@value='6']")
    st_text=('xpath',"//td[@align='right']/td/font[1]")
    yz_text=('xpath',"//td[@align='right']/td/font[2]")

    #打开网页
    def  page_shop_cart_web(self):
        self.base_open_web(self.url)
    #点击购物车
    def page_shop_cart_click(self):
        self.base_click(self.cart_click)
    #点击服装
    def page_shop_cart_add_click(self):
        self.base_click(self.fuz_content)
    #点击商品
    def page_shop_cart_add_pag(self):
        self.base_click(self.add_pag)
    #加入购物车
    def page_shop_cart_add(self):
        self.base_click(self.add_cart)
    # 点击结算
    def page_shop_cart_buy(self):
        self.base_click(self.buy)

    #选择省的标签
    def page_addr_select_province(self,your_content):
        self.base_select(self.S_select,your_content)
    #选择市的标签
    def page_addr_slect_city(self,your_content):
        self.base_select(self.C_select,your_content)
    #选择区的标签
    def page_addr_district(self,your_content):
        self.base_select(self.q_slect,your_content)
    #输入姓名
    def page_addr_input_name(self,your_content):
        self.base_input_content(self.name,your_content)
    #输入地址
    def page_addr_input_aadr(self,your_content):
        self.base_input_content(self.addr,your_content)
    #输入电话
    def page_addr_input_tel(self,your_content):
        self.base_input_content(self.tel,your_content)
    #点击配送至这个地址
    def page_addr_click(self):
        self.base_click(self.addr_click)
    #验证输入地址是否成功
    def page_addr_is_sucess(self):
        result=self.base_get_text(self.addr_info)
        return result
    #修改地址
    def page_addr_update_addr(self):
        self.base_click(self.update_addr_click)
    #点击申通
    def page_addr_st_click(self):
        self.base_click(self.st_click)
    #点击邮政
    def page_addr_yz_click(self):
        self.base_click(self.yz_click)
    #获取申通文本  是否成功
    def page_addr_st_is_success(self):
        self.base_get_text(self.st_text)
    #获取邮政文本 是否成功
    def page_addr_yz_is_success(self):
        self.base_get_text(self.st_text)
    def page_addr_quit(self):
        self.base_quit()












if __name__ == '__main__':
    p1=Page_add_addr(create_browser_op(r'C:\Users\86183\AppData\Local\Google\Chrome\User Data'))
    p1.page_shop_cart_web()
    p1.page_shop_cart_click()  #点击购物车
    p1.page_shop_cart_add_click() #点击服装按钮(购物车添加商品)
    p1.page_shop_cart_add_pag()  #点击包
    p1.page_shop_cart_add()  #加入购物车
    p1.page_shop_cart_buy() #结算按钮
    time.sleep(5)
    # p1.page_addr_select_province('四川省')
    # time.sleep(5)
    # p1.page_addr_slect_city('成都市')
    # time.sleep(5)
    # p1.page_addr_district('温江区')
    # time.sleep(5)
    # p1.page_addr_input_name('张三')
    # p1.page_addr_input_aadr('光华公园')
    # p1.page_addr_input_tel('18398924851')
    p1.page_addr_click()
    time.sleep(5)
    # print(p1.page_addr_is_sucess())
    p1.page_addr_update_addr()
    # p1.page_addr_st_click()
    time.sleep(5)
    # print(p1.page_addr_st_is_success())













